package com.atguigu.gmall.user.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/api/user")
public class ApiUserAddressController {
    @Autowired
    private UserService userService;

    @GetMapping("/auth/get/user/address/list")
    public Result<List<UserAddress>> getUserAddressList(HttpServletRequest request) {
        String userId = request.getHeader("userId");
        if (StringUtils.isEmpty(userId)) {
            return Result.<List<UserAddress>>fail().message("没有获取到有效 userId！");
        }
        List<UserAddress> userAddressList = userService.getUserAddressList(userId);
        return Result.ok(userAddressList);
    }
}
